import VueRouter from 'vue-router'

import HomeContainer from './components/tabbar/HomeContainer.vue'
import MemberContainer from './components/tabbar/MemberContainer.vue'
import SearchContainer from './components/tabbar/SearchContainer.vue'
import ShopcarContainer from './components/tabbar/ShopcarContainer.vue'

import Newslist from './components/news/Newslist.vue'
import Newsinfo from './components/news/Newsinfo.vue'
import PhotoList from './components/photos/PhotoList.vue'
import PhotoInfo from './components/photos/PhotoInfo.vue'

import GoodsList from './components/goods/GoodsList.vue'
import GoodsInfo from './components/goods/GoodsInfo.vue'
import GoodsDesc from './components/goods/GoodsDesc.vue'
import GoodsComments from './components/goods/GoodsComments.vue'
import Login from './Login.vue'
import Register from './Register.vue'


// 创建路由对象
var router = new VueRouter({
    routes: [
        {path: '/', redirect: '/home'},
        {path:'/login',component:Login},
        {path:'/register',component:Register},
        {path: '/home', component: HomeContainer},
        {path: '/member', component: MemberContainer},
        {path: '/shopcar', component: ShopcarContainer},
        {path: '/search', component: SearchContainer},
        {path: '/home/newslist', component: Newslist},
        {path: '/home/newsinfo/:id', component: Newsinfo},
        {path: '/home/photolist',component:PhotoList},
        {path: '/home/photoinfo',component:PhotoInfo},
        {path:'/home/goodslist',component:GoodsList},
        {path:'/home/goodsinfo/:id',component:GoodsInfo},
        //name:路由命名
        {path:'/home/goodsdesc/:id',component:GoodsDesc,name:'goodsdesc'},
        {path:'/home/goodscomments/:id',component:GoodsComments,name:'goodscomments'},


    ],
    linkActiveClass:' mui-active' //Tabbar的点击类
})
router.beforeEach((to,from,next)=>{

    //  当前路由为登录页/login,/register,或者账号密码登录信息正确
    if(to.path=='/login'||to.path=='/register'||(localStorage.getItem('login')=='true')){
        next();
    }//否则进行跳窗提示并跳转到/login
    else{
        alert("请先登录");
        next('/login')
    }
});
// 把路由对象暴露出去
export default router